/**
 * Created by Administrator on 2017/5/30.
 */
!(function(){
    var appeals = {
        userId: $.fn.cookie('userId'),
        isLogin: $.fn.cookie('isLogin'),
        init:function(){
            this.submit();
        },
        submit:function(){
            var self = this;
            var params  = {};
            var $form = $("#formAppeals");
            $form.form();
            $('#btn-publish').on('click',function(){
                params = {
                    userId:self.userId,
                    message:$('#messages').val()
                };
                $form.validate(function(error){
                    if(error){
                        $.toptips(error.msg,'info');
                    }else{
                        $.ajax({
                            url:API_URL+PUBLISH_FEEDBACKS_URL,
                            type:'post',
                            dataType:'jsonp',
                            data:params,
                            beforeSend:function(){
                                $('#btn-publish').addClass('disabled');
                            },
                            success:function(data){
                                if(data.ok==true){
                                    $.toast('申诉成功!');
                                    $.alert('我们会尽快审核！谢谢合作！');
                                    setTimeout(function(){
                                        window.location.href='my_products_list.html';
                                    },3000)
                                }
                            },
                            complete:function(){
                                $('#btn-publish').removeClass('disabled');
                            },
                            error:function(data){
                                $.toptips(data.msg,'info');
                            }
                        });

                    }
                });
            })
        }
    }
    $(function(){
        appeals.init();
    })
})(Zepto);